Skip to content

[Bug Fix] #620132: Prevent IRS 1099 data on vendor ledger entries of non-1099 vendors - #9880

Open
ventselartur wants to merge 5 commits into
mainfrom
bugs/620132-IRS
Open

[Bug Fix] #620132: Prevent IRS 1099 data on vendor ledger entries of non-1099 vendors#9880
ventselartur wants to merge 5 commits into
mainfrom
bugs/620132-IRS

Conversation

@ventselartur

@ventselartur ventselartur commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Bug Reference

ADO work item #620132It is possible to specify 1099 information in vendor ledger entry even though the vendor is not 1099

Summary

IRS 1099 fields on a vendor ledger entry could be filled in for a vendor that is not subject to 1099 reporting. This PR adds a validation that the vendor has an IRS 1099 Vendor Form Box Setup record for the selected reporting period before any of the IRS 1099 fields can be set on the entry.

Root Cause

The OnValidate triggers of IRS 1099 Reporting Period (10031), IRS 1099 Form No. (10032) and IRS 1099 Form Box No. (10033) in tableextension 10035 "IRS 1099 Vendor Ledger Entry" only called IRS1099FormDocument.CheckIfVendLedgEntryAllowed, which blocks edits on entries already linked to an IRS 1099 form document. Nothing verified that the vendor is subject to 1099 reporting. Because these fields are editable on pageextension 10048 "IRS 1099 Vendor Ledger Entries", a user could assign a reporting period / form / form box to a ledger entry of a vendor with no 1099 setup at all.

Changes Made

  • src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al: added CheckVendorSubjectFor1099Reporting(VendorNo; PeriodNo). It exits when the period is blank (so clearing the fields is always allowed) and otherwise raises Vendor %1 is not set up for IRS 1099 reporting in the reporting period %2. when no IRS 1099 Vendor Form Box Setup record exists for that (period, vendor) pair.
  • src/Apps/US/IRSForms/app/src/Extensions/IRS1099VendorLedgerEntry.TableExt.al: the three OnValidate triggers now call the new check, guarded by a non-blank test on the field being validated so clearing a field remains unconditionally allowed.
  • src/Apps/US/IRSForms/test/src/IRS1099DocumentTests.Codeunit.al: three new tests (see below).

report 10038 "IRS 1099 Propagate Vend. Setup" validates the same three fields, but only for vendors that already have an IRS 1099 Vendor Form Box Setup record, so it is unaffected — confirmed by the full test run.

Implementation Process

  • Fix iterations: 1 of 5
  • Compilation: OK - IRS Forms, IRS Forms Test Library and IRS Forms Tests all compile clean
  • Tests: OK - all tests related to this change pass

Test Evidence

Test run: codeunit 148010 "IRS 1099 Document Tests" on an on-premise NST (US localization).

Pre-Fix Test Results (Baseline)

Baseline run against the unfixed product code:

FAIL ValidateIRS1099PeriodOnVendLedgEntryForNon1099Vendor
     An error was expected inside an ASSERTERROR statement
     (Validate("IRS 1099 Reporting Period", ...) succeeded silently on a vendor
      with no 1099 setup - the bug)

PASS ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor
PASS ClearIRS1099PeriodOnVendLedgEntryForNon1099Vendor

Post-Fix Test Results (Final)

PASS ValidateIRS1099PeriodOnVendLedgEntryForNon1099Vendor   (was red)
PASS ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor
PASS ClearIRS1099PeriodOnVendLedgEntryForNon1099Vendor
PASS ChangeIRSDataInVendorLedgerEntryConnectedToFormDocument
PASS IRS1099CodeInPurchInvHeaderUpdatedWhenChangedInVendLedgEntry
PASS IRS1099CodeInPurchCrMemoHeaderUpdatedWhenChangedInVendLedgEntry

Full codeunit run: 39 passed, 2 failed.

Pre-existing failures (NOT caused by this change)

Both failures were reproduced on this environment with the product fix reverted, and fail
identically with and without the change:

Test Error Assessment
IRS1099CodeInPurchaseHeaderWhenChangePostingDateAfterAddingLine IRS 1099 Reporting Amount must be equal to '-1.13' ... Current value is '-1' Pre-existing; amount/VAT rounding, unrelated to vendor-setup validation
PartialPaymentCreatesLineDetailWithDifferentCalculatedAndReportingAmounts Cannot post because one or more transactions have dates after the working date Pre-existing; environment work-date/data dependency in the test library

Iteration Summary

  • Baseline iteration 1: initial tests written; the positive test hit a duplicate IRS 1099 Vendor Form Box Setup key because it assigned a second form box for the same (period, vendor). Test corrected.
  • Baseline iteration 2: red baseline confirmed - the repro test fails, the two guard tests pass.
  • Fix iteration 1: added the setup check and wired it into the three triggers - all tests related to the change pass.

Test Coverage

  • Existing tests pass
  • New tests added for bug scenario
  • Regression test for work item #620132 (vendor with 1099 setup is unaffected)
  • Edge cases covered (clearing the fields stays allowed)

Testing Checklist

  • Automated tests: All passing
  • Manual testing: create a vendor without a 1099 code, post a purchase invoice and a payment applied to it, open Vendor Ledger Entries and try to set IRS 1099 Reporting Period / Form No. / Form Box No. — an error should appear
  • Regression testing: IRS 1099 propagation report, purchase document posting for 1099 vendors, form document creation
  • Performance: negligible — one keyed Get per field validation

Review Notes

  • The check is keyed on IRS 1099 Vendor Form Box Setup (period + vendor), the same source of truth used by UpdateIRSDataInPurchHeader and GetVendorIRS1099FormBoxSetupAsOfDate.
  • Clearing any of the three fields is deliberately never blocked, so existing entries on vendors that lost their 1099 setup can still be cleaned up.

🤖 Generated by the bc-fix-bug skill

AB#620132

Bug #620132: It is possible to specify 1099 information in vendor ledger entry even though the vendor is not 1099

Root Cause:
- The OnValidate triggers of "IRS 1099 Reporting Period", "IRS 1099 Form No."
  and "IRS 1099 Form Box No." in tableextension 10035 "IRS 1099 Vendor Ledger
  Entry" only guarded against entries already linked to an IRS 1099 form
  document. Nothing verified that the vendor is subject to 1099 reporting, so
  a user could assign a reporting period, form and form box on the Vendor
  Ledger Entries page for a vendor with no "IRS 1099 Vendor Form Box Setup"
  record at all.

Changes:
- Added CheckVendorSubjectFor1099Reporting to codeunit 10037 "IRS 1099 Vendor
  Form Box". It exits for a blank period and otherwise errors when no "IRS 1099
  Vendor Form Box Setup" record exists for the (period, vendor) pair.
- Called the new check from the three OnValidate triggers in tableextension
  10035, guarded so that clearing the fields remains allowed.

Test Coverage:
- ValidateIRS1099PeriodOnVendLedgEntryForNon1099Vendor (new, reproduces the bug)
- ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor (new, regression guard)
- ClearIRS1099PeriodOnVendLedgEntryForNon1099Vendor (new, clearing stays allowed)
- 42/42 tests in codeunit 148010 "IRS 1099 Document Tests" pass
- Number of fix iterations: 1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b132ff13-1ace-428c-a844-844eee2d1932
@github-actions github-actions Bot added the Finance GitHub request for Finance area label Jul 31, 2026
Add the [FEATURE] [AI test] marker above the [SCENARIO 620132] line in the
three new tests, matching the convention used by the other tests in the
IRSForms test codeunits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b132ff13-1ace-428c-a844-844eee2d1932
@github-actions github-actions Bot added this to the Version 29.0 milestone Jul 31, 2026
@ventselartur
ventselartur marked this pull request as ready for review August 6, 2026 19:02
@ventselartur
ventselartur requested a review from a team August 6, 2026 19:02
@ventselartur
ventselartur requested a review from a team as a code owner August 6, 2026 19:02
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 1

Recommendation: Accept with Suggestions

What this PR does

This PR fixes a gap in IRS 1099 data entry: the three OnValidate triggers on IRS 1099 Reporting Period, IRS 1099 Form No., and IRS 1099 Form Box No. in tableextension 10035 previously allowed a user to assign 1099 data to a vendor ledger entry even when the vendor had no IRS 1099 Vendor Form Box Setup record for that period.

The fix adds a new procedure CheckVendorSubjectFor1099Reporting in codeunit 10037 that does a keyed Get on IRS 1099 Vendor Form Box Setup using (PeriodNo, VendorNo) — the clustered primary key — and raises a clear error if no record exists. The procedure early-exits when PeriodNo is blank, so clearing any of the three fields remains unconditionally allowed. Each trigger guards the call with a non-blank check on the field being validated, which is the correct pattern. The Get key order matches the table PK (Period No., Vendor No.), so the existence check is accurate. The changes to IRS1099VendorTests.Codeunit.al adapt the existing ChangeIRSDataInVendorLedgerEntry test to supply a 1099-enrolled vendor for the ledger entry (required now that validation blocks non-1099 vendors) and add Round() to avoid the amount precision issue flagged in the pre-existing test failure list.

Suggestions

S1 - ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor does not exercise the new check
The test validates IRS 1099 Form Box No. directly without first setting IRS 1099 Reporting Period, so CheckVendorSubjectFor1099Reporting receives PeriodNo = '' and exits immediately. The check is never reached, so the test would also pass for a non-1099 vendor. Consider setting a period on the entry before calling Validate("IRS 1099 Form Box No.", ...), which would actually exercise the guard added in this PR.

S2 - IRS 1099 Form No. trigger silently skips the check when period is blank
In the Form No. OnValidate, CheckVendorSubjectFor1099Reporting is called with "IRS 1099 Reporting Period" as the period. If a user sets Form No. before setting a period (possible on the page), PeriodNo is '' and the check exits early with no error. The primary flow (via Reporting Period validate → cascades Validate("IRS 1099 Form No.", '')) prevents this in practice, but a direct edit of Form No. without a prior period bypasses the guard.

Risk assessment and necessity

Risk: The change adds validation at the table level on three OnValidate triggers in tableextension 10035. Any code path that calls Validate on these fields for a non-1099 vendor (batch imports, data migrations, or background jobs that set IRS fields without the full UI flow) will now raise an error where it previously succeeded silently. The IRS 1099 Propagate Vend. Setup report is unaffected because it only processes vendors that already have a setup record. Regression surface is limited to US localization only.

Necessity: The fix is clearly needed. Allowing non-1099 vendor ledger entries to carry IRS reporting data is a data integrity problem: those entries would be included in incorrect 1099 form calculations. The change is well-scoped and targeted.


[AI-PR-REVIEW] version=1 promptVersion=1 system=github pr=9880 round=1 by=alexei-dobriansky at=2026-08-07T12:07:19Z lastSha=e559fd464eea6ab5f14e850e6dd155704c7f1a5a reviewKey=273e973e6667e6d809359917131ee88dcab1bb15a53d8910c3d4bffd73ca843c suggestions=S1@d811307f,S2@977fac7d

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ Stale Status Check Deleted

The Pull Request Build workflow run for this PR was older than 72 hours and has been deleted.

📋 Why was it deleted?

Status checks that are too old may no longer reflect the current state of the target branch. To ensure this PR is validated against the latest code and passes up-to-date checks, a fresh build is required.


🔄 How to trigger a new status check:

  1. 📤 Push a new commit to the PR branch, or
  2. 🔁 Close and reopen the PR

This will automatically trigger a new Pull Request Build workflow run.

Comment thread src/Apps/US/IRSForms/app/src/VendorFormBox/IRS1099VendorFormBox.Codeunit.al Outdated
The build's new-warning gate failed on two AA0206 diagnostics in the
IRS Forms test project. Both new tests assigned the result of
CreateSingleFormBoxInReportingPeriod to a FormBoxNo variable that was
never read. The call is kept as a statement so the form box is still
created as part of the test setup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 2

Recommendation: Accept with Suggestions

What this PR does

The PR adds table-level validation so IRS 1099 fields on a vendor ledger entry cannot be set for a vendor that has no IRS 1099 Vendor Form Box Setup record for the selected period. The new round only removes unused local variables from two tests, so it does not change the product behavior.

The product fix is still targeted. It checks the vendor and period before setting the three IRS 1099 fields and still allows clearing the period. The remaining review points are about test strength and one direct-validation edge case from round 1.

Status of previous suggestions
ID Title Status Author response
S1 ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor does not exercise the new check Not addressed No response found.
S2 IRS 1099 Form No. trigger silently skips the check when period is blank Not addressed No response found.
New observations (commits since round 1)

None - the new commit only removes unused variables from tests.

Risk assessment and necessity

Risk: The product change adds validation to posted vendor ledger entry IRS 1099 fields in the US IRS Forms app. This can block imports or background jobs that previously set these fields for vendors without 1099 setup, but that is the invalid data path the bug describes. The latest commit is test-only cleanup and has very low regression risk.

Necessity: The change is needed because non-1099 vendors should not carry IRS reporting data on vendor ledger entries. The scope remains narrow and tied to the bug scenario.


[AI-PR-REVIEW] version=1 promptVersion=2 system=github pr=9880 round=2 by=alexei-dobriansky at=2026-08-14T10:13:30Z lastSha=c74e438f8d56338d7875cae5575e1feccd68b41a reviewKey=na suggestions=S1@d811307f:notaddressed,S2@977fac7d:notaddressed parentRound=1

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Stale Status Check Deleted

The Pull Request Build workflow run for this PR was older than 72 hours and has been deleted.

📋 Why was it deleted?

Status checks that are too old may no longer reflect the current state of the target branch. To ensure this PR is validated against the latest code and passes up-to-date checks, a fresh build is required.


🔄 How to trigger a new status check:

  1. 📤 Push a new commit to the PR branch, or
  2. 🔁 Close and reopen the PR

This will automatically trigger a new Pull Request Build workflow run.

- Raise an actionable ErrorInfo with a navigation action to the IRS 1099
  Vendor Form Box Setup page instead of a dead-end Error dialog
- Make ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor set a reporting
  period first so it actually exercises the new vendor-setup guard
- Add a negative test covering the IRS 1099 Form No. and Form Box No.
  guards for a vendor without 1099 setup

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 3

Recommendation: Accept with Suggestions

What this PR does

This PR blocks IRS 1099 fields on vendor ledger entries when the vendor has no IRS 1099 Vendor Form Box Setup for the selected reporting period. The latest commit addresses review feedback by making the positive test validate the reporting period and form before the form box, adding negative tests for Form No. and Form Box No., and changing the setup error to an ErrorInfo with a navigation action.

The main data-integrity path is now covered better. The validation still checks the keyed (Period No., Vendor No.) setup record before accepting non-blank IRS 1099 values, and clearing remains allowed because the helper exits for a blank period. I did not find a new issue in the latest commit, but one direct-validation edge case from the previous review remains open.

Status of previous suggestions
ID Title Status Author response
S1 ValidateIRS1099FormBoxOnVendLedgEntryFor1099Vendor does not exercise the new check Addressed The test now validates IRS 1099 Reporting Period and IRS 1099 Form No. before validating IRS 1099 Form Box No., so it reaches the new setup check.
S2 IRS 1099 Form No. trigger silently skips the check when period is blank Not addressed No response found.
New observations (commits since round 2)

None - the new commit adds the missing test coverage for the main data-integrity path and improves the error message action. The remaining open point is still S2 from the earlier review.

Risk assessment and necessity

Risk: The product change affects editable IRS 1099 fields on posted vendor ledger entries in the US IRS Forms app. It can now stop imports, page edits, or background code that tries to stamp IRS data on a non-1099 vendor, but that is the invalid data path the bug is meant to prevent. The latest commit is test and error-message work, so its new regression surface is small.

Necessity: The change is needed because non-1099 vendors should not carry IRS reporting data on vendor ledger entries. The scope remains narrow, and the tests now cover the financial data-integrity path that must be protected.


[AI-PR-REVIEW] version=1 promptVersion=2 system=github pr=9880 round=3 by=alexei-dobriansky at=2026-08-19T13:07:35Z lastSha=02a830bf8b3e24bc7cc8a1f313fbf4e42e4aa40f reviewKey=e885bf1fc891e796413cc7bba4cb410e037e87d6ae927a615ada9a7e747106c9 suggestions=S1@d811307f:addressed,S2@977fac7d:notaddressed parentRound=2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Finance GitHub request for Finance area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants